//
//  iosstreamBasic.hpp
//  learnC++
//
//  Created by liuzhibing on 2018/7/9.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef iosstreamBasic_hpp
#define iosstreamBasic_hpp

#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;
class First_iostream {
    
public:
    
    First_iostream(){
        
    }
    
    ~First_iostream(){
        
    }
    
    void testIO(){
        
        cout << "Enter you age: " << endl;
        
        int age = 0;
        
        cin >> age;
        
        if (age <= 0)
        {
            // In this case we'll use the insertion operatior on cerr to print an error message
            cerr << "Oops, you entered an invalid age!" << endl;
            exit(1);
        }
        cout << "You entered " << age << " years old" << endl;
        
    }
    
    void testCin(){
        char buf[10];
        cin.ignore(3);//忽略前3个字符
        cin >> setw(10) >> buf;//可用于限制从流中读入的字符数。 要使用setw（）
        
        cout << "========" << buf << endl;
        
//        char ch;
//        while (cin >> ch)//会丢弃用户输入的空格
//            cout << ch;
        
//        char ch;
//        while (cin.get(ch))//可获取空格
//            cout << ch;

//        char strBuf[11];
//        cin.get(strBuf, 11);
//        cout << strBuf << endl;//指定获取长度
        
//        还有一个名为getline（）的函数与get（）完全相同，但也会读取换行符，get()不会
        
    }
    
    
};

#endif /* iosstreamBasic_hpp */
